{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. 异常练习\n",
    "1.1 让用户输入两个数字，计算第一个数除以第二个数，输出计算结果\n",
    "1.2 加上异常处理代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入错误\n",
      "程序运行结束\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    num1 = eval(input(\"请输入第1个数:\"))\n",
    "    num2 = eval(input(\"请输入第2个数:\"))\n",
    "    result = num1/num2\n",
    "except:\n",
    "    print(\"输入错误\")    \n",
    "else:\n",
    "    print(\"两数相除，结果=\",result)\n",
    "finally:\n",
    "    print(\"程序运行结束\")    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[95, 100, 77, 88, 58, 69, 87, 30, 95, 65]\n",
      "77\n",
      "95\n",
      "100\n",
      "95 100 77 100 58 69 87 30 95 65 \n",
      "95 100 77 100 58 69 87 30 95 65 \n",
      "100 30 776\n",
      "[30, 58, 65, 69, 77, 87, 95, 95, 100, 100]\n",
      "[95, 100, 77, 100, 58, 69, 87, 30, 95, 65, 50]\n",
      "[95, 100, 77, 100, 58, 60, 69, 87, 30, 95, 65, 50]\n",
      "[95, 100, 77, 100, 60, 69, 87, 30, 95, 65, 50]\n",
      "4\n",
      "[50, 65, 95, 30, 87, 69, 60, 100, 77, 100, 95]\n",
      "1\n",
      "[]\n"
     ]
    }
   ],
   "source": [
    "# 2.1. 定义一个列表存放10个学生成绩\n",
    "maths = [95,100,77,88,58,69,87,30,95,65]\n",
    "print(maths)\n",
    "# 2.2. 打印第3个学生的成绩、打印倒数第2个学生成绩\n",
    "# 下标从0开始   后面往前从-1开始\n",
    "print(maths[2])  \n",
    "print(maths[-2])\n",
    "# 2.3. 将第4个学生的成绩改为100分\n",
    "maths[3] = 100\n",
    "print(maths[3])\n",
    "# 2.4. 遍历打印所有学生成绩\n",
    "for m in maths:\n",
    "    print(m,end=\" \")\n",
    "print(\"\")\n",
    "\n",
    "for i in range(len(maths)):\n",
    "    print(maths[i],end=\" \")\n",
    "print(\"\")\n",
    "\n",
    "# 2.5. 打印最高分和最低分和总分\n",
    "print(max(maths),min(maths),sum(maths))\n",
    "\n",
    "# 2.6. 打印排序后的学生成绩\n",
    "print(sorted(maths))\n",
    "# 2.7. 添加一个50分在最后\n",
    "maths.append(50)\n",
    "print(maths)\n",
    "# 2.8 插入一个60在位置6\n",
    "maths.insert(5,60)\n",
    "print(maths)\n",
    "# 2.9 弹出第5个学生成绩\n",
    "maths.pop(4)\n",
    "print(maths)\n",
    "# 2.10. 查找60分同学排在第几个\n",
    "print(maths.index(60))\n",
    "# 2.11 翻转列表\n",
    "maths.reverse()\n",
    "print(maths)\n",
    "# 2.12 统计60分同学有几个\n",
    "print(maths.count(60))\n",
    "# 2.13 复制一份列表\n",
    "maths2 = maths.copy()\n",
    "print(maths2)\n",
    "# 2.14 清空所有成绩\n",
    "maths.clear()\n",
    "print(maths)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
